package com.company;

import java.util.Scanner;

/**
 * @author zhangjian
 * @data 2023/3/19
 * @Version 1.0
 * @Descripion
 */
public class 最大子矩阵之和2 {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int row = sc.nextInt();
        int lie = sc.nextInt();
        int[][] array = new int[row][lie];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < lie; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        System.out.println(maxSubMatrix(row,lie, array));
    }

    private static int maxSubMatrix(int row,int lie, int[][] arr) {
        int sum = Integer.MIN_VALUE;
        int[] tempArray = new int[lie];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < lie; j++) {
                tempArray[j] = 0;
            }
            // 把第i行到第j行相加,对每一次相加求出最大值
            for (int j = i; j < row; j++) {
                for (int k = 0; k < lie; k++) {
                    tempArray[k] += arr[j][k];
                }
                int max = maxSubArray(tempArray);
                sum = Integer.max(sum, max);
            }
        }
        return sum;
    }

    private static int maxSubArray(int[] arr) {
        int sum = Integer.MIN_VALUE;
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            temp += arr[i];
            if (temp > 0) {
                sum = Integer.max(sum, temp);
            }
        }
        return sum;
    }
}
